﻿using System;
using System.IO;
using System.Reflection;
using AutoAllocService.Configs;
using AutoAllocService.Map;
using AutoAllocService.Messaging;
using AutoAllocService.Services;
using log4net;
using log4net.Config;
using log4net.Repository;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace AutoAllocService
{
    class Program
    {
        public static AppSettings AppSetting { get; private set; }

        static void Main(string[] args)
        {
            AppSetting = JsonConvert.DeserializeObject<AppSettings>(System.IO.File.ReadAllText("appsettings.json"));
            ILoggerRepository repository = LogManager.GetRepository(Assembly.GetEntryAssembly());
            XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));

            var log = LogManager.GetLogger(typeof(Program));
            log.Info("Running");
            Run();
            //Start();
        }

        private static void Run()
        {

            //var result = DriverService.GetDrivers(30.585158000000000000000000, 103.965305000000000000000000, "iSYP6x137wJN03OE").Result;
            //var mqttHelper = new MqttHelper();
            //mqttHelper.Run();

            var taskPool = new AllocTaskPool();

            //new MqttHelper().Run();

            RabbitMqHelper.Instance.Consume("test", msg =>
            {
                taskPool.StartTask(msg);
            });
        }

        private static void Start()
        {
            var result = DriverService.GetDrivers(30.535776691307614000000000, 104.065854665714570000000000,
                "jJAC6r13j7GrQunC").Result;
        }
    }
}
